package com.ccc.scala.base7_collection

import scala.collection.mutable.ArrayBuffer


object Collection04_Map {
  def main(args: Array[String]): Unit = {
    // 集合 - map
    val array = ArrayBuffer(1, 2, 3, 4)

    def mapFunction(num: Int): Int = {
      num * 2
    }

    println(array.map(mapFunction)) // ArrayBuffer(2, 4, 6, 8)

    // 简化
    println(array.map((x: Int) => {
      x * 2
    })) // ArrayBuffer(2, 4, 6, 8)

    println(array.map((x) => {
      x * 2
    })) // ArrayBuffer(2, 4, 6, 8)

    println(array.map(x => x * 2)) // ArrayBuffer(2, 4, 6, 8)

    println(array.map(_ * 2)) // ArrayBuffer(2, 4, 6, 8)

  }

}
